<?php

class userControl extends Control {

     public function index() {
        $uid = $_SESSION['user']['uid'];
        $db = M('user');
        $user = $db->where("uid='$uid'")->find();
        //分配画板
        $huaban = M('huaban');
        $huabandata = $huaban->where("uid='$uid'")->limit(9)->all();
        $huabancon = $huaban->where("uid='$uid'")->count();
        $caiji = M('user_img');
        $caijicon = $caiji->where("uid=$uid")->count();
        $this->assign('caijicon', $caijicon); //分配采集数量
        $this->assign('huabancon', $huabancon); //分配画板数量
        $this->assign('huabandata', $huabandata); //分配画板
        $this->assign('user', $user); //用户信息


        $this->display();
    }

    public function caiji() {
        $this->display();
    }

    public function edit_huaban() {
        $hid = $_GET['hid'];
        $db = M('huaban');
        $count = $db->where("hid=$hid")->count();
        if ($count != 0) {
            $cate = M('category');
            $category = $cate->all();
            $this->assign('category', $category);

            $title = $db->where("hid='$hid'")->find();
            $this->assign('title', $title);
        }

        $this->display();
    }

    public function edit_huaban_p() {
        if (!empty($_POST['hid'])) {
            $hid = $_POST['hid'];
            $title = $_POST['title'];
            $tid = $_POST['tid'];

            $db = M('huaban');
            $dat = "update $db->tableName set title='$title',tid='$tid' where hid='$hid'";
            $ds = $db->exe($dat);
            if ($ds == 1) {
                $this->success('修改成功');
            } else {
                $this->success('无修改');
            }
        }
    }

    public function delhuaban() {
        if (!empty($_POST['a'])) {
            $hid = $_POST['a'];
            $db = M('huaban');
            $ds = M('user_img');
            $cun = $ds->where("hid='$hid'")->count();
            if ($cun > 0) {
                $img = $ds->where("hid='$hid'")->all();
                $url = dirname($_SERVER['SCRIPT_FILENAME']);
                foreach ($img as $v) {
                    if (is_file($url . '/' . $v['img'])) {

                        unlink($url . '/' . $v['img']);
                    }
                    $u_img="delete from h_user_img where hid='$hid'";
                }
                $dat = "delete from $db->tableName where hid='$hid'";
            }

            $data = $db->exe($dat);
            $data2 = $ds->exe($u_img);
            if ($data == 1) {
                echo 1;
            } else {
                echo 0;
            }
        }
    }
}
?>
